package com.geostar.gmp.action;

import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.geostar.gmp.dao.IPc_dataDao;
import com.geostar.gmp.global.ConfigValue;
import com.geostar.gmp.model.Pc_data;
import com.geostar.gmp.model.factory.SessionFactory;
import com.geostar.gmp.utils.DateUtils;
import com.geostar.gmp.utils.JsonUtils;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 文件名:Pc_dataAction.java
 * 功能: 获取时段电脑状态action
 * 目前支持方法
 * --------------------------------------
 * 初始版本 
 * 作者: yesong
 * 时间: Apr 8, 2014
 */
public class Pc_dataAction extends ActionSupport{

	public static Logger logger = LoggerFactory.getLogger(Pc_dataAction.class);
	
	private static final long serialVersionUID = -6990631540637949386L;

	/** 需要查看的电脑IP **/
	private String pc_ip;

	/** 查询时间段电脑状态值 **/
	private List<Pc_data> dataList;
	
	/** 时段开始时间 **/
	private String start_time;
	
	/** 时段结束时间 **/
	private String end_time;
	
	/** Test **/
	private String result;
	
	public String findPc_data() throws Exception{
		
		SqlSession session = SessionFactory.createSession();
		
		IPc_dataDao pc_dataDao = session.getMapper(IPc_dataDao.class);
		
		Pc_data pc_data = new Pc_data();
		pc_data.setIp("127.0.0.1");
		pc_data.setEnd_time(this.end_time!=null?end_time:DateUtils.getLongTime());
		pc_data.setStart_time(this.start_time!=null?start_time:DateUtils.getBeforeTime(ConfigValue.BeforeTime)); 
		
		this.dataList = pc_dataDao.findPc_data(pc_data);
		
		SessionFactory.closeSession(session);
		
		this.result = JsonUtils.bean2Json(this.dataList);
		logger.info("Bean To Json:" + this.result);
		return "json_list";
	}
	
	public String getPc_ip() {
		return pc_ip;
	}

	public void setPc_ip(String pc_ip) {
		this.pc_ip = pc_ip;
	}

	public List<Pc_data> getDataList() {
		return dataList;
	}

	public void setDataList(List<Pc_data> dataList) {
		this.dataList = dataList;
	}

	public String getStart_time() {
		return start_time;
	}

	public void setStart_time(String start_time) {
		this.start_time = start_time;
	}

	public String getEnd_time() {
		return end_time;
	}

	public void setEnd_time(String end_time) {
		this.end_time = end_time;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
}
